import React from 'react';
import { useNavigate } from 'react-router-dom';
import { Form, Input, Button, Divider } from 'antd';

const Login = () => {

    const navigate = useNavigate();

    const onFinish = async (values) => {
        console.log('Received values:', values);
        // 在这里处理登录逻辑，可以是向后端发送请求验证用户信息等



    if (values.username !== 'admin' || values.password !== '123456') {
        // setErrorMessage('Username or password is incorrect');
        console.log('Username or password is incorrect');
    } else {
        // setErrorMessage('Login successful');
        // localStorage.setItem('isLoggedIn', 'true');
        navigate('/admin');
    }

    
    //   const loginData = {
    //       user: values.username,
    //       pwd: values.password
    //   };

    //   try {
    //     // 发送POST请求
    //     const response = await axios.post('https://fw.nongkeyu.com/audio_api/login/', loginData);
    //     const data = response.data;
        
    //     if (data.ans) {
    //       setErrorMessage('Login successful');
    //       localStorage.setItem('isLoggedIn', 'true');
    //       navigate('/admin');
    //     } else {
    //       setErrorMessage('Username or password is incorrect');
    //     }
    //   } catch (error) {
    //     console.error('登录请求失败', error);
    //     setErrorMessage('Username or password is incorrect');
    //   }
    };

    return (
        <div className='login-container'>
            <Form name="login" onFinish={onFinish}>
                <Form.Item
                    name="username"
                    rules={[{ required: true, message: 'Please input your username!' }]}
                >
                    <Input placeholder="Username" />
                </Form.Item>
                <Form.Item
                    name="password"
                    rules={[{ required: true, message: 'Please input your password!' }]}
                >
                    <Input.Password placeholder="Password" />
                </Form.Item>
                <Form.Item>
                    <Button block type="primary" htmlType="submit">
                        Log in
                    </Button>
                </Form.Item>
            </Form>
        </div>
    );
};

export default Login;
